package com.jd.controller;

import com.jd.pojo.User;
import com.jd.service.UserService;
import com.jd.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @Transactional
    public SysResult login(@RequestBody User user){
        String token = userService.login(user);
        if (token==null){
            return SysResult.fail();
        }
        return SysResult.success();
    }

    @PutMapping("/insert")
    @Transactional
    public void insert(User user){
        userService.insert(user);
    }
}
